package seqlist.leetcode;

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;


public class 优先级队列 {
    public int lastStoneWeight(int[] stones) {
//       PriorityQueue<Integer> pq = new PriorityQueue<Integer>((a, b) -> b - a);
        Queue<Integer> pq= new PriorityQueue<>(new Comparator<Integer>() {

            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });

        for (int i : stones){
            pq.offer(i);
        }
        while (pq.size()>1){
            int a = pq.poll();
            int b = pq.poll();
            pq.offer(a-b);
        }
        return pq.isEmpty()? 0:pq.poll();
    }
}
